//
//  FATabBarController.swift
//  FoodAdd
//
//  Created by 千峰1 on 16/11/3.
//  Copyright © 2016年 FoodAddGroup. All rights reserved.
//

import UIKit

class FATabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        self.createViewControllers()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
}

//MARK: - 视图控制器
extension FATabBarController {
    
    func createViewControllers() {
        
        //实例化
        let homeVC = HomeViewController()
        let homeNav = UINavigationController(rootViewController: homeVC)
        
        let SubjectVC = SubjectViewController()
        let SubjectNav = UINavigationController(rootViewController: SubjectVC)
        
        let meVC = MeViewController()
        let meNav = UINavigationController(rootViewController: meVC)
        
        let StoreVC = StoreViewController()
        let StoreNav = UINavigationController(rootViewController: StoreVC)
        
        let ShoppingBasketVC = ShoppingBasketViewController()
        let ShoppingBasketNav = UINavigationController(rootViewController: ShoppingBasketVC)
        
        let vcArray = [homeVC,SubjectVC,StoreVC,ShoppingBasketVC,meVC]
        let navArray = [homeNav,SubjectNav,StoreNav,ShoppingBasketNav,meNav]
        
        self.viewControllers = navArray
        
        //标题
        let titleArray = ["首页","专题","店铺","购物篮","我的"]
        let unselectedImageArray = ["huiben_u","faxian_u","tiaoman_u","zhuanti_u","wode_u"]
        let selectedImageArray = ["huiben_d","faxian_d","tiaoman_d","zhuanti_d","wode_d"]
        
        //        //设置导航
        for i in 0..<vcArray.count {
            let vc = vcArray[i]
            //设置导航的颜色
            vc.navigationController?.navigationBar.barTintColor = UIColor.darkGrayColor()
            //            //设置导航不透明
            //            vc.navigationController?.navigationBar.translucent = false
            //            //设置标题
            //            vc.navigationItem.title = titleArray[i]
            //            //设置导航标题的属性
            ////            vc.navigationController?.navigationBar.titleTextAttributes = [NSFontAttributeName:UIFont.boldSystemFontOfSize(18),NSForegroundColorAttributeName:UIColor.whiteColor()]
        }
        
        //设置tabBar
        for i in 0..<navArray.count {
            
            let nav = navArray[i]
            //设置标题
            nav.tabBarItem.title = titleArray[i]
            //未选中的图片
            nav.tabBarItem.image = UIImage(named: unselectedImageArray[i])?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
            //选中的图片
            nav.tabBarItem.selectedImage = UIImage(named: selectedImageArray[i])?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        }
        
    }
}
